const router = require('express').Router();

router.post("/beacon", (req, res) => {
    const data = req.body;
    res.send({
        statusCode: 200,
        message: 'success',
        data: data
    })
})

router.get('/pixel', (req, res) => {
    const data = req.query.data;
    // 发送一个1x1的透明像素，确保<img>加载完成
    const pixel = Buffer.from([
        0x47, 0x49, 0x46, 0x38, 0x39, 0x61,
        0x01, 0x00, 0x01, 0x00, 0x80, 0x00,
        0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,
        0xFF, 0x21, 0xF9, 0x04, 0x01, 0x00,
        0x00, 0x01, 0x00, 0x2C, 0x00, 0x00,
        0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
        0x00, 0x02, 0x02, 0x44, 0x01, 0x00,
        0x3B
    ]);
    res.setHeader('Content-Type', 'image/gif');
    res.send(pixel);
})

module.exports = router